home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_selectkeys.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  177 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. #ifdef DO_PICKSHORTCUTS    /* Support code */
  17.  
  18. VOID
  19. LTP_SelectKeys(LayoutHandle *handle,ObjectNode *group)
  20. {
  21.     LONG            bunch;
  22.     ObjectNode *    node;
  23.     ULONG            page;
  24.     STRPTR *        lines;
  25.  
  26.     SCANPAGE(group,node,page)
  27.     {
  28.         bunch = 0;
  29.         lines = NULL;
  30.  
  31.         switch(node->Type)
  32.         {
  33.             case GROUP_KIND:
  34.  
  35.                 LTP_SelectKeys(handle,node);
  36.                 break;
  37.  
  38.             case TEXT_KIND:
  39.  
  40.                 if(!node->Special.Text.UsePicker)
  41.                     break;
  42.  
  43.             case PASSWORD_KIND:
  44.             case STRING_KIND:
  45.             case FRACTION_KIND:
  46.  
  47.                 if(node->Type != TEXT_KIND && node->Special.String.UsePicker)
  48.                     bunch = 255;
  49.  
  50.             case BUTTON_KIND:
  51.  
  52.                 if(node->Type == BUTTON_KIND)
  53.                 {
  54.                     if(!node->NoKey && node->Special.Button.Lines)
  55.                         lines = node->Special.Button.Lines;
  56.                 }
  57.  
  58.             case BOOPSI_KIND:
  59.             case CHECKBOX_KIND:
  60.             case INTEGER_KIND:
  61.  
  62.                 bunch++;
  63.  
  64. #ifdef DO_POPUP_KIND
  65.             case POPUP_KIND:
  66. #endif    /* DO_POPUP_KIND */
  67. #ifdef DO_TAB_KIND
  68.             case TAB_KIND:
  69. #endif    /* DO_TAB_KIND */
  70. #ifdef DO_LEVEL_KIND
  71.             case LEVEL_KIND:
  72. #endif    /* DO_LEVEL_KIND */
  73. #ifdef DO_TAPEDECK_KIND
  74.             case TAPEDECK_KIND:
  75. #endif    /* DO_TAPEDECK_KIND */
  76.  
  77.             case LISTVIEW_KIND:
  78.             case MX_KIND:
  79.             case CYCLE_KIND:
  80.             case PALETTE_KIND:
  81.             case SCROLLER_KIND:
  82.             case SLIDER_KIND:
  83.  
  84.                 bunch++;
  85.  
  86.                 if(node->Label && !node->Key && !node->NoKey)
  87.                 {
  88.                     LONG    i,len,code,glyph;
  89.                     STRPTR    label;
  90.  
  91.                     do
  92.                     {
  93.                         if(lines)
  94.                         {
  95.                             if(!(label = *lines++))
  96.                                 break;
  97.                         }
  98.                         else
  99.                             label = node->Label;
  100.  
  101.                         len = strlen(label);
  102.  
  103.                         for(i = 0 ; i < len ; i++)
  104.                         {
  105.                             glyph    = ToLower(label[i]);
  106.                             code    = -1;
  107.  
  108.                             switch(bunch)
  109.                             {
  110.                                 case 1:    // Support increment & decrement
  111.  
  112.                                     if(LTP_Keys[0][glyph] && LTP_Keys[1][glyph])
  113.                                         code = LTP_Keys[0][glyph];
  114.  
  115.                                     break;
  116.  
  117.                                         // Any one will do
  118.  
  119.                                 case 2:
  120.  
  121.                                     if(LTP_Keys[0][glyph])
  122.                                         code = LTP_Keys[0][glyph];
  123.                                     else
  124.                                     {
  125.                                         if(LTP_Keys[1][glyph] && LTP_Keys[0][glyph])
  126.                                         {
  127.                                             if(ToLower(LTP_Keys[1][glyph]) == glyph)
  128.                                                 code = LTP_Keys[0][glyph];
  129.                                         }
  130.                                     }
  131.  
  132.                                     break;
  133.                             }
  134.  
  135.                             if(code != -1 && !handle->Keys[code])
  136.                             {
  137.                                 if(lines)
  138.                                 {
  139.                                     node->Special.Button.KeyStroke = &label[i];
  140.  
  141.                                     lines = NULL;
  142.                                 }
  143.                                 else
  144.                                 {
  145.                                     STRPTR newLabel;
  146.  
  147.                                     if(newLabel = LTP_Alloc(handle,len + 2))
  148.                                     {
  149.                                         node->Label = newLabel;
  150.  
  151.                                         if(i)
  152.                                             CopyMem(label,newLabel,i);
  153.  
  154.                                         newLabel[i] = '_';
  155.  
  156.                                         strcpy(&newLabel[i + 1],label + i);
  157.                                     }
  158.                                 }
  159.  
  160.                                 node->Key = code;
  161.  
  162.                                 handle->Keys[code] = handle->Keys[LTP_Keys[1][code]] = TRUE;
  163.  
  164.                                 break;
  165.                             }
  166.                         }
  167.                     }
  168.                     while(lines);
  169.                 }
  170.  
  171.                 break;
  172.         }
  173.     }
  174. }
  175.  
  176. #endif    /* DO_PICKSHORTCUTS */
  177.